package db

import (
	"github.com/lerryxiao/gorm"
	_ "github.com/lerryxiao/gorm/dialects/sqlite"
)

// 变量定义
var (
	db *gorm.DB
)

// ConnectDB 连接db
func ConnectDB(dbfile string) (err error) {
	db, err = gorm.Open("sqlite3", dbfile)
	return
}

// GetDB 获取db
func GetDB() *gorm.DB {
	return db
}

// Close 关闭
func Close() {
	if db != nil {
		db.Close()
		db = nil
	}
}
